package com.example.demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@SuppressWarnings("all")
public class sort {
    public static long minimumValueAfterDispel (int[] nums) {
        // write code here
        for(int i=0;i<2;i++){
            int temp = nums[i];
            for(int j=0;j<nums.length;j++){
                if(nums[j]-temp>=0){
                    nums[j]=nums[j]-temp;
                }
            }
        }
        long sum = 0;
        for(int i=0;i<nums.length;i++){
            sum = sum + nums[i];
        }
        System.out.println(sum);
        return sum;
    }

    public static void main(String[] args) {
        List<String> list = Arrays.asList(new String[]{"1,张三，91", "2,李四，80", "3,张三，80", "4,王五，90", "5,王五，90"});
//        for (String a:list
//        ) {
//            System.out.println(a);
//        }

        System.out.println("after");
        List arrayList = new ArrayList(list);
        for (Object a : arrayList
        ) {
            System.out.println(a);
        }
        for (int i = 0; i < arrayList.size(); i++) {
            for (int j = i + 1; j < arrayList.size(); j++) {
                if (arrayList.get(i).toString().substring(2, 4).equals(arrayList.get(j).toString().substring(2, 4))) {
                    Float a = Float.valueOf(arrayList.get(i).toString().substring(5, 7)) + Float.valueOf(arrayList.get(j).toString().substring(5, 7));
                    a = a / 2;

                    arrayList.remove(j);
//                    String s = arrayList.get(i).toString().substring(0,5)+a;
                    arrayList.set(i, arrayList.get(i).toString().substring(0, 5) + a);
                }
            }
        }

        for (int i = 0; i < arrayList.size(); i++) {
            for (int j = i + 1; j < arrayList.size(); j++) {
                if (Float.valueOf(arrayList.get(i).toString().substring(5, arrayList.get(i).toString().length())) < Float.valueOf(arrayList.get(j).toString().substring(5, arrayList.get(j).toString().length()))) {


                    String s = new String(arrayList.get(i).toString());
                    arrayList.set(i, arrayList.get(j));
                    arrayList.set(j, s);
                }
            }
        }

        System.out.println("去重：" + 115 / 2);
        for (Object a : arrayList
        ) {
            System.out.println(a);
        }


        minimumValueAfterDispel(new int[]{2, 1, 3});
///////////////////////////////////////////////////////////


//        String[] tokens = new String[]{"20", "10", "+", "30", "*"};
        String[] tokens = new String[]{"40", "130", "50", "/", "+"};
//        String[] tokens = new String[]{"30", "30", "*"};
        System.out.println(tokens.length);
        int a = 0;
        int g = 0;
        for (int i = 0; i < tokens.length; i++) {
            System.out.println(i);
                if (tokens[i].equals("+") || tokens[i].equals("-") || tokens[i].equals("*") || tokens[i].equals("/")) {
                    switch (tokens[i]) {
                        case "+":
                            a = Integer.valueOf(tokens[i - 2]) + Integer.valueOf(tokens[i - 1]);
                            tokens[i - 2] = a + "";
                            for (int j = i - 1; j < tokens.length; j++) {
                                if (j + 2 < tokens.length) {
                                    tokens[j] = tokens[j + 2];
                                }
                            }
                            tokens = Arrays.copyOf(tokens, tokens.length - 2);

                            break;
                        case "-":
                            a = Integer.valueOf(tokens[i - 2]) - Integer.valueOf(tokens[i - 1]);
                            tokens[i - 2] = a + "";
                            for (int j = i - 1; j < tokens.length; j++) {
                                if (j + 2 < tokens.length) {
                                    tokens[j] = tokens[j + 2];
                                }
                            }
                            tokens = Arrays.copyOf(tokens, tokens.length - 2);
                            break;
                        case "*":
                            a = Integer.valueOf(tokens[i - 2]) * Integer.valueOf(tokens[i - 1]);
                            tokens[i - 2] = a + "";
                            for (int j = i - 1; j < tokens.length; j++) {
                                if (j + 2 < tokens.length) {
                                    tokens[j] = tokens[j + 2];
                                }
                            }
                            tokens = Arrays.copyOf(tokens, tokens.length - 2);
                            break;
                        case "/":
                            a = Integer.valueOf(tokens[i - 2]) / Integer.valueOf(tokens[i - 1]);
                            tokens[i - 2] = a + "";
                            for (int j = i - 1; j < tokens.length; j++) {
                                if (j + 2 < tokens.length) {
                                    tokens[j] = tokens[j + 2];
                                }
                            }
//                        ArrayUtils.remove(tokens,tokens.length-1);
                            tokens = Arrays.copyOf(tokens, tokens.length - 2);
                            break;

                    }
                    i=0;
                    System.out.println("tokens.length = " + tokens.length);
                    System.out.println(tokens[0]);

                }
            }

    }
}
